package indi.zhifa.recipe.bailan.framework.auth.service.impl;

import indi.zhifa.recipe.bailan.framework.auth.dao.IBaseAuthNodeRelevantDao;
import indi.zhifa.recipe.bailan.framework.auth.dao.service.IUserDbService;
import indi.zhifa.recipe.bailan.framework.auth.dao.service.IUserRelevantDao;
import indi.zhifa.recipe.bailan.framework.auth.entity.BaseTokenObject;
import indi.zhifa.recipe.bailan.framework.auth.entity.dto.TokenObject;
import indi.zhifa.recipe.bailan.framework.auth.entity.po.BaseUserEntity;
import indi.zhifa.recipe.bailan.framework.auth.entity.po.UserEntity;
import indi.zhifa.recipe.bailan.framework.auth.service.ILoginService;
import indi.zhifa.recipe.bailan.framework.auth.util.IBaseTokenUtil;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
public class LoginServiceImpl extends BaseLoginServiceImpl implements ILoginService {

    private final IUserDbService mUserDbService;

    public LoginServiceImpl(IUserRelevantDao pUserRelevantDao,
                            IBaseAuthNodeRelevantDao pDepartmentRelevantDao,
                            PasswordEncoder pPasswordEncoder,
                            IBaseTokenUtil pBaseTokenUtil,
                            IUserDbService pUserDbService) {
        super(pUserRelevantDao, pDepartmentRelevantDao, pPasswordEncoder, pBaseTokenUtil);
        mUserDbService = pUserDbService;
    }

    protected BaseUserEntity checkUserEntity(Long pId) {
        UserEntity userEntity = mUserDbService.check(pId);
        return userEntity;
    }

    @Override
    protected BaseTokenObject fillOtherInfo(BaseTokenObject pBaseTokenObject, BaseUserEntity pBaseUserEntity) {
        TokenObject tokenObject = (TokenObject)pBaseTokenObject;
        UserEntity userEntity = (UserEntity)pBaseUserEntity;
        tokenObject.setNickName(userEntity.getNickName());
        return tokenObject;
    }

}
